ITK Programmer's Guide


 

Table of contents | Intro | General | TCP Low Level | TCP High Level | UDP | DNS | PPP
Encoding/Decoding | Internet Config | Goodies | Cryptography | Appendix

 

Chapter 11 : Cryptography routines

   

   

Chapter contents:


About this chapter...

This chapter describes cryptography routines.



About ITK Digest Calculation routine

A digest is like some "super-checksum" calculated on some data. They can be used as digital signatures or to transfer encrypted information.The original information cannot be recovered from the digest.

For example, MD5 digests can be used to had a digital signature to emails to ensure that the message content has not been changed (see RFC#1544).

MD5 digests are also used in the POP3 APOP command which allows user authentication with transferring the user's password (see RFC#1939).

MD5 and SHA digests are also used in the SSL protocol.

Using ITK digest calculation routines

The first step is to initialise a digest calculation using ITK_DigestInit.
Then data are added to the calculation using the ITK_DigestAdd and ITK_DigestBlob routines
Finally, ITK_DigestCalc is called to get the final digest value (returned as a string).

ITK_DigestInit

Syntax:

digestRef := ITK_DigestInit(digestType)


Description:

ITK_DigestInit initialises a new digest calculation and returns a digest reference which will be needed in the next step of a digest calculation (ITK_DigestAdd or ITK_DigestBlob, then ITK_DigestCalc).


Params:

In/Out

Parameter

Type

   

Example or note

->

digestType

Longint

Digest type

1 = SHA digests
2 = MD2 digests
5 = MD5 digests

<-

digestRef

Longint

Digest Reference

   


Example:

$digestRef := ITK_DigestInit(2) ` start MD2 digest calculation
ITK_DigestAdd($digestRef;"Here is some text")
ITK_DigestAdd($digestRef;"and some more")
ITK_DigestBlob($digestRef;myBlob)
$myDigest := ITK_DigestCalc($digestRef) ` get the result
Back to top


ITK_DigestAdd

Syntax:

ITK_DigestAdd(digestRef;text)


Description:

Adds some text to a current digest calculation referenced by digestRef.

This routine may be called several times during a digest calculation.


Params:

In/Out

Parameter

Type

   

Example or note

->

digestRef

Longint

Digest reference

As returned by ITK_DigestInit

->

text

Text

Text to add to the calculation

   


Example:

$digestRef := ITK_DigestInit(2) ` start MD2 digest calculation
         ITK_DigestAdd($digestRef;"Here is some text")
         ITK_DigestAdd($digestRef;"and some more")
ITK_DigestBlob($digestRef;myBlob)
$myDigest := ITK_DigestCalc($digestRef) ` get the result
Back to top


ITK_DigestBlob

Syntax:

ITK_DigestBlob(digestRef;blob)


Description:

Adds some data contained in a blob to a current digest calculation referenced by digestRef.

This routine may be called several times during a digest calculation.


Params:

In/Out

Parameter

Type

   

Example or note

->

digestRef

Longint

Digest reference

As returned by ITK_DigestInit

->

blob

Blob

Data to add to the calculation

   


Example:

$digestRef := ITK_DigestInit(2) ` start MD2 digest calculation
ITK_DigestAdd($digestRef;"Here is some text")
ITK_DigestAdd($digestRef;"and some more")
         ITK_DigestBlob($digestRef;myBlob)
$myDigest := ITK_DigestCalc($digestRef) ` get the result
Back to top


ITK_DigestCalc

Syntax:

digest := ITK_DigestCalc(digestRef;digestFormat)


Description:

Terminates the digest calculation and returns the calculated digest according to the format option.

After calling this routine, the digestRef previously returned by ITK_DigestInit is not valid anymore.


Params:

In/Out

Parameter

Type

   

Example or note

->

digestRef

Longint

Digest reference

As returned by ITK_DigestInit

->

digestFormat

Longint

Desired format for the digest result

0 = 8bit text
1 = lowercase hexadecimal encoded string

<-

digest

Text

Digest calculation result

   


Example:

$digestRef := ITK_DigestInit(2) ` start MD2 digest calculation
ITK_DigestAdd($digestRef;"Here is some text")
ITK_DigestAdd($digestRef;"and some more")
ITK_DigestBlob($digestRef;myBlob)
$myDigest := ITK_DigestCalc($digestRef) ` get the result
Back to top


ITK_Rot13Text

Syntax:

encodedText := ITK_Rot13Text(originalText)


Description:

Applies ROT13 "light encryption" to some text.

ROT13 is an email standard to hide some text. It is not a real encryption, only a shift in characters to make some text unreadable.

ROT13 is auto-reversible, apply it a second time to get the original text back.
So: ROT13(ROT13(text)) = text

If the original text was 7bit only, the resulting text will still be a 7bit only text.


Params:

In/Out

Parameter

Type

   

Example or note

->

originalText

Text

Original text

   

<-

encodedText

Text

Encoded text

   


Example:

$rot13 := ITK_Rot13Text("Hello")
Back to top


ITK_Rot13Blob

Syntax:

ITK_Rot13Blob(theBlob)


Description:

Applies ROT13 "light encryption" to a blob.

ROT13 is an email standard to hide some data. It is not a real encryption, only a shift in characters to make some data unreadable.

ROT13 is auto-reversible, apply it a second time to get the original data back.

If the original data was 7bit only, the resulting data will still be a 7bit only text.

The original blob is directly "encrypted" to avoid a copy in memory.


Params:

In/Out

Parameter

Type

   

Example or note

<->

theBlob

Blob

Original Blob

   


Example:

ITK_Rot13Blob(myBlob)
Back to top


CQ/31-Jul-98